package com.white.seckill;

/**
 * <p>
 * 响应
 * </p>
 *
 * @author white
 * @since 2022/4/6
 */
public class Result<T> {

    /**
     * 相应码
     */
    private final int code;

    /**
     * 是否成功
     */
    private final boolean success;

    /**
     * 提示消息
     */
    private final String msg;

    /**
     * 附加消息
     */
    private final T data;

    public Result(int code, boolean success, String msg, T data) {
        this.code = code;
        this.success = success;
        this.msg = msg;
        this.data = data;
    }

    public static Result<?> success(){
        return new Result<>(200,true,"",null);
    }

    public static <T> Result<T> success(T data){
        return new Result<>(200,true,"",data);
    }

    public static Result fail(String msg){
        return new Result(500,false,msg,null);
    }

    public int getCode() {
        return code;
    }

    public boolean isSuccess() {
        return success;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }
}
